//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "fn_dragProne.sqf"
#include <btc_macros.h>
TRACE_1("Start",_this);

private ["_injured","_id","_pullanims"];
_injured = _this select 0;

_pullanims = ["amovppnemstpsraswrfldnon","amovppnemrunslowwrfldf","amovppnemsprslowwrfldfl","amovppnemsprslowwrfldfr","amovppnemrunslowwrfldb","amovppnemsprslowwrfldbl","amovppnemsprslowwrfldr","amovppnemstpsraswrfldnon_turnl","amovppnemstpsraswrfldnon_turnr","amovppnemrunslowwrfldl","amovppnemrunslowwrfldr","amovppnemsprslowwrfldb","amovppnemrunslowwrfldbl","amovppnemsprslowwrfldl","amovppnemsprslowwrfldbr"];

_injured attachto [player, [0, 2, 0]];
_id = player addAction [RED_TEXT("Drop"),{(_this select 3) call FUNC(release)},[], 9, true, true, "", "true"];

BTCR_pveh_drag = [1,_injured];publicVariable "BTCR_pveh_drag";

TRACE_1("Animation",animationstate player);
private ["_act","_veh_selected","_array","_array_veh","_name_veh","_text_action","_action_id","_pos"];
_act = 0;_veh_selected = objNull;_array_veh = [];
while {!isNull player && alive player && !isNull _injured && alive _injured && format ["%1", _injured getVariable ["BTC_need_revive",1]] == "1" && BTCR_dragging &&  ((tolower(animationstate player) in _pullanims))} do
{
	_array = nearestObjects [player, ["Air","LandVehicle"], 5];
	_array_veh = [];
	{if (_x emptyPositions "cargo" != 0) then {_array_veh = _array_veh + [_x];};} foreach _array;
	if (count _array_veh == 0) then {_veh_selected = objNull;};
	if (count _array_veh > 0 && _veh_selected != _array_veh select 0) then 
	{
		_veh_selected    = _array_veh select 0;
		_name_veh        = getText (configFile >> "cfgVehicles" >> typeof _veh_selected >> "displayName");
		_text_action     = RED_TEXT("Load wounded in " + (_name_veh));
		_action_id = player addAction [_text_action,{(_this select 3) spawn FUNC(loadIn)},[_injured,_veh_selected], 7, true, true];
		_act  = 1;
	};
	if (count _array_veh == 0 && _act == 1) then {player removeAction _action_id;_act = 0;};
	sleep 0.1;
};
TRACE_1("Animation",animationstate player);
if (_act == 1) then {player removeAction _action_id;};
//player playMoveNow "AmovPknlMstpSrasWrflDnon";
_injured setVariable ["BTC_dragged",0,true];
if (format ["%1",_injured getVariable ["BTC_need_revive",1]] == "1") then {
	detach _injured;
	_pos = (getPos _injured);
	_pos set [2,0.1];
	_injured setPos _pos;
	_injured playMoveNow "AinjPpneMstpSnonWrflDb_release";
};
player removeAction _id;
BTCR_dragging = false;
TRACE("End");